package com.ljq.cksp.service.impl;

import com.ljq.cksp.dao.LawDao;
import com.ljq.cksp.pojo.Law;
import com.ljq.cksp.service.LawService;
import com.ljq.cksp.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.List;

/**
 * @Author:ljq
 * @Date:2020/4/22
 */
@Service
public class LawServiceImpl implements LawService {
    @Autowired
    LawDao lawDao;

    @Override
    public Page<Law> query(String keyword, int start, int size) {
        start = start<0?0:start;
        return lawDao.findByTitle(keyword, PageRequest.of(start, size));
    }

    @Override
    public void saveFromFile(File file) {
        List<Law> laws = JsonUtil.json2Laws(file);
        lawDao.saveAll(laws);
    }
}
